package com.briup.cms.web.controller;

import com.briup.cms.bean.Category;
import com.briup.cms.exception.CustomerException;
import com.briup.cms.service.ICategoryService;
import com.briup.cms.utils.Message;
import com.briup.cms.utils.MessageStatus;
import com.briup.cms.utils.MessageUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "栏目管理相关接口")
@RestController
@RequestMapping("/auth/category")
public class CategoryController {

    @Autowired
    private ICategoryService service;

    @ApiOperation("通过Id删除栏目")
    @ApiImplicitParam(name="id",value = "需要删除的id",dataType = "int")
    @DeleteMapping("/deleteById")
    public Message deleteById(int id){
//        try {
            service.deleteById(id);
//        } catch (Exception e) {
//            throw new CustomerException(MessageStatus.SPECIFIED_QUESTIONED_ERROR);
//        }
        return MessageUtil.success();
    }

    @ApiOperation("保存栏目信息")
    @PostMapping("/save")
    public Message save(Category category){
        service.saveCategory(category);
        return MessageUtil.success(category);
    }


    @ApiOperation("更新栏目信息")
    @PutMapping("/update")
    public Message update(Category category){
        service.updateCategory(category);
        return MessageUtil.success(category);
    }

    @ApiOperation("批量删除栏目信息")
    @DeleteMapping("/batchDelete")
    public Message batchDelete(int[] ids) {
        service.batchDelete(ids);
        return MessageUtil.success(ids);
    }

    @ApiOperation("分页查询栏目")
    @GetMapping("/page/queryAll")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页",dataType = "int",required = true),
            @ApiImplicitParam(name = "pageSize",value = "页面大小",dataType = "int",required = true)
    })
    public Message pageQueryAll(int pageNum, int pageSize){
        return MessageUtil.success(service.pageQueryAll(pageNum,pageSize));
    }

    @ApiOperation("查询所有栏目")
    @GetMapping("/find/all")
    public Message findAll(){
        return MessageUtil.success(service.findAll());
    }

}
